package common;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: shenran
 * Date: 13-7-15
 * Time: 下午5:06
 * To change this template use File | Settings | File Templates.
 */
public class HTTPTaskManager {
    private List<HttpRequestTask> m_task_list;
    private static HTTPTaskManager  instance=null;
    public static HTTPTaskManager getInstance() {
        if (instance == null)
            instance = new HTTPTaskManager();
        return instance;
    }

    public void AppendTask(HttpRequestTask httpTask) {
        m_task_list.add(httpTask);
        RunNext();
    }

    void RunNext()
    {
          if(m_task_list.size()>0)
          {
              HttpRequestTask task=m_task_list.get(0);
              Thread thread = new Thread(task);
              thread.start();
          }
    }

    public void didComplete(HttpRequestTask runnable) {
        m_task_list.remove(runnable);
        RunNext();
    }
}
